package Structure;

import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;


/**
 * Structure to represent a word with all its attributes. Especially its meanings and translations. 
 * @author Tony
 *
 */
public class Word {

	public String word;

	/**
	 * language of the word
	 */
	public String language;

	/**
	 * language of the wiktionary the word come from
	 */
	public String languageOfContent;

	public Translation[] translations;

	/**
	 * list the explanations to the meanings 
	 */
	public Map<String, String> mapMeaningToExplanation;
	
	public Word(String word, String language, String languageOfContent) {
		this.word = word;
		this.language = language;
		this.languageOfContent = languageOfContent;
		this.translations = new Translation[0];
		this.mapMeaningToExplanation=new TreeMap<String, String>();
	}

	public Word(String word, String language, Translation[] translation,
			String languageOfContent) {
		this.word = word;
		this.language = language;
		this.translations = translation;
		this.languageOfContent = languageOfContent;
		this.mapMeaningToExplanation=new TreeMap<String, String>();
	}

	@Override
	public String toString() {
		String txt = "word: " + word + "\tlanguage: " + language;
		txt+="\nexplanations";
		for(Entry<String,String> meaningToExplenation: this.mapMeaningToExplanation.entrySet()){
			txt+="\n"+meaningToExplenation.getKey()+"\t"+meaningToExplenation.getValue();
		}
			
		txt+="\ntranslations";	
		for (int i = 0; i < translations.length; i++) {
			txt += "\n" + translations[i].toString();
		}
		return txt;
	}

}
